package model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Objects;

@NoArgsConstructor
@AllArgsConstructor
@Data
public class Book implements java.io.Serializable{
	private Integer BookId;  //图书编号
	private String BookName;  //图书名称
	private String BookType;  //图书类别
	private String BookAuthor;  //图书作者
	private String BookPublisher; //出版社
	private String BookAvailability;  //图书借阅情况 为1表示可借
	private String BookBorrowId;  //借阅人学号
	private String BookBorrowTime; //借阅时间
	private String BookReturnPeriod;//图书归还期限
	//private int Limit = 3;//表示借书最长时间为Limit个月

	public boolean borrowBook(String bookBorrowId,String bookBorrowTime) throws Exception {
		if(Objects.equals(BookAvailability, "1")){
			BookAvailability = "0";
			BookBorrowId = bookBorrowId;
			BookBorrowTime = bookBorrowTime;
			BookReturnPeriod = addData(3,BookBorrowTime);
			return true;
		} else{
			return false;
		}
	}
	public boolean returnBook(String bookBorrowId, int bookId){
		BookAvailability = "1";
		BookBorrowId = "";
		return true;
	}
	public String addData(int m,String s1) throws Exception {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
		Date d = sdf.parse(s1);
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(d);
		calendar.add(Calendar.MONTH, m);
		Date dA = calendar.getTime();
		return sdf.format(dA);
	}

	/*
	@Override
	public String toString() {
		return "Book [测试=" + id + ", bookName=" + bookName + ", author=" + author + ", sex=" + sex + ", price=" + price
				+ ", bookTypeId=" + bookTypeId + ", bookTypeName=" + bookTypeName + ", bookDesc=" + bookDesc + "]";
	}
	*/
}
